package com.wlz.learnjuc.sync;

/**
 *  synchronized 锁 的是 对象
 * @author wlz
 * @date 2022-04-16  7:56 下午
 */
public class SynchronizedLockOnObject {

    public static Object object = new Object();

    private Integer stock = 10;

    public void decrStock(){
        //T1,T2
        synchronized (object){
            --stock;
            if(stock <= 0){
                System.out.println("库存售罄");
                return;
            }
        }
    }

    public static void main(String[] args) {
        SynchronizedLockOnObject lockOnObject = new SynchronizedLockOnObject();
        lockOnObject.decrStock();
    }
}
